package com.xyz.tag.html.attribute;

import com.xyz.tag.html.XYHtmlConstants;
import com.xyz.tag.html.XYIAttribute;
import com.xyz.tag.util.StringUtil;


public class XYAttribute implements XYIAttribute {

  private static final long serialVersionUID = 5475759902995632006L;
  private String name;
  private String value;

  public XYAttribute( String name ) {
    this( name, null );
  }

  public XYAttribute( String name, String value ) {
    this.name = name;
    this.value = value;
  }

  @Override
  public String draw() {
    StringBuffer sb = new StringBuffer();
    if ( !StringUtil.isEmpty( name ) ) {
      sb.append( name );
      if ( !StringUtil.isEmpty( value ) ) {
        sb.append( XYHtmlConstants.sign_eq ).append( XYHtmlConstants.sign_quot ).append( getValue() )
            .append( XYHtmlConstants.sign_quot );
      }
    }
    return sb.toString();
  }

  @Override
  public int hashCode() {
    return name.hashCode();
  }

  @Override
  public boolean equals( Object o ) {
    return name.equals( ( (XYAttribute)o ).getName() );
  }

  public String getName() {
    return name;
  }

  public void setName( String name ) {
    this.name = name;
  }

  public String getValue() {
    return value;
  }

  public void setValue( String value ) {
    this.value = value;
  }
}